import com.alibaba.excel.EasyExcel;
import com.situ.library.pojo.entity.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class EasyExcelDemo {

    @Test
    public void testWrite() {
        List<UserData> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            UserData userData  = new UserData();
            userData.setId(i);
            userData.setName("excel: " + i);
            list.add(userData);
        }
        //设置excel文件的路径和文件名
        String fileName = "E:\\excel\\001.xlsx";
        //调用EasyExcel写数据到excel
        EasyExcel.write(fileName, UserData.class).sheet("用户信息").doWrite(list);
    }

    @Test
    public void testRead() {
        String fileName = "E:\\excel\\001.xlsx";
        EasyExcel.read(fileName, UserData.class, new ExcelListener()).sheet().doRead();
        //StringBuilder  StringBuffer
    }
}